

    $(document).ready(function () {
        query();
    });



    function query( ) {




        //发送ajax;
        $.ajax(
            {
                type: "post",
                url: "/operate/list",
                data: {'confType':10},
                dataType: "json",
                success: function (data) {
                    var data = data.data;
                    if(data){
                        var tmpl=bt('ruleslisttmp', data);
                        // $('ruleslist').html(tmpl);
                        document.getElementById('ruleslist').innerHTML=tmpl;
                        return tmpl;

                    }

                }, error: function () {
                alert("报错了");
            }
            }
        );
        $.ajax(
            {
                type: "post",
                url: "/operate/list",
                data: {'confType':20},
                dataType: "json",
                success: function (data) {
                    var data = data.data;
                    if(data){
                        var tmpl=bt('ruleslisttmp2', data);
                        // $('ruleslist').html(tmpl);
                        document.getElementById('ruleslist2').innerHTML=tmpl;
                        return tmpl;
                    }

                }, error: function () {
                alert("报错了");
            }
            }
        );

    }


    function clear() {
        $('.result-project-name').val(''),
            $('.time input').val(''),
            $('.result-remark').val('');
    }







  





function rateclear() {
    $('.rate-project-name').val(''),
        $('.time-range input').val(''),
        $('.call-num input').val(''),
        $('.rate-remark').val('');
}
function cancel_btn(){
    //取消
    //清空
    rateclear();
    $('#rate-pop').hide();
    clear();
    $('#result-pop').hide();
}
//新增通话频次参数
function save_thpc() {
    var confName_edit=  $('#thpc_confName').val();
    var confEname_edit=  $('#thpc_confEname').val();
    var confValue_edit= $('#thpc_confValue').val();
    var bak_edit= $('#thpc_bak').val();
    var remark_edit= $('#thpc_remark').val();
    var allId_edit=$('#allIdthpc').val();
    var allConfig={confValue:confValue_edit, bak:bak_edit,confName:confName_edit ,confEname:confEname_edit,remark:remark_edit,allId:allId_edit,confType:20};
        var   url="/operate/update";
        if(!allId_edit){
            url="/operate/add";
        }
    $.ajax({
        type:"post",
        url:url,
        data:allConfig,
        dataType: "json",
        success:function(data){
            if(data.code==0){
                alert(data.msg);
            }
            query();
        },
        error:function(){
            alert("报错啦");
        }
    });


    //前端的添加放在ajax成功回调函数里   新增的数据默认为停用

    //ajax
    rateclear();
    $('#rate-pop').hide();
    query();

}
function save_thxg() {
    var confName_edit=  $('#confName_edit').val();
    var confEname_edit=  $('#confEname_edit').val();
    var confValue_edit= $('#confValue_edit').val();
    var remark_edit= $('#remark_edit').val();
    var allId_edit=$('#allIdthxg').val();
    var allConfig={confValue:confValue_edit, remark:remark_edit,confName:confName_edit,confEname:confEname_edit ,allId:allId_edit,confType:10};
    var   url="/operate/update";
    if(!allId_edit){
        url="/operate/add";
    }
    $.ajax({
        type:"post",
        url:url,
        data:allConfig,
        dataType: "json",
        success:function(data){
            query();
        },
        error:function(){
            alert("报错啦");
        }
    });
    rateclear();
    cancel_btn();

}

function edit_show_thpc(obj) {

    //弹出第一次的提示框
    $('#operate-before-pop').show();
    //点击确定 弹出编辑框
    $('.operate-before-confirm').off('click').on('click', function () {
        $('#operate-before-pop').hide();
        //需要回填数据
        $('#rate-pop .cms-modal-title').html('修改通话频次参数');
             var tr = $(obj).parents("tr");
            $('.rate-project-name').val(tr.find('.confName').text());
            $('#thpc_confEname').val(tr.find('.confEname').text());
            $('.time-range input').val(tr.find('.confValue').text());
            $('.call-num input').val(tr.find('.bak').text());
            $('.rate-remark').val(tr.find('.remark').text());
            $('#allIdthpc').val($(obj).attr('id-value'));
            $('#rate-pop').show();
        $('.rate-project-name').attr("readonly","readonly");
        $('#thpc_confEname').attr("readonly","readonly");
    })
    //点击取消
    $('.operate-before-cancel').off('click').on('click', function () {
        $('#operate-before-pop').hide();
    })

    $('.rate-cancel').off('click').on('click', function () {
        //取消
        //清空
        rateclear();
        $('#rate-pop').hide();
    })


}function edit_show_thxg(obj) {

        var that = this;

        //弹出第一次的提示框
        $('#operate-before-pop').show();
        //点击确定 弹出编辑框
        $('.operate-before-confirm').off('click').on('click', function () {
            $('#operate-before-pop').hide();
            //需要回填数据
            $('#result-pop .cms-modal-title').html('修改通话效果参数');
            var tr = $(obj).parents("tr");
            $('#confName_edit').val(tr.find('.confName').text());
            $('#confEname_edit').val(tr.find('.confEname').text());
            $('#confValue_edit').val(tr.find('.confValue').text());
            $('#remark_edit').val(tr.find('.remark').text());
            $('#allIdthxg').val($(obj).attr('id-value'));
            $('#result-pop').show();
            $('#confName_edit').attr("readonly","readonly");
            $('#confEname_edit').attr("readonly","readonly");
            var name=tr.find('.confEname').text();
            if(name=='call_least_price'){
             $('#unit_1').html("元")
            }else if(name=='call_good_price'){
                $('#unit_1').html("元")
            }else{
                $('#unit_1').html("秒")

            }


        })
        //点击取消
        $('.operate-before-cancel').off('click').on('click', function () {
            $('#operate-before-pop').hide();
        })

    }
//启用停用
function changeStatus(obj ) {
    var that = this;
    //当前状态为启用
    //弹出第一次的提示框
    $('#operate-before-pop').show();
    //点击确定 弹出编辑框
    $('.operate-before-confirm').off('click').on('click', function () {
        $('#operate-before-pop').hide();
        //第二次提示弹出
        $('#operate-after-pop').show();
        $('.operate-after-confirm').off('click').on('click', function () {
            activeRule(obj);
            if ($(that).hasClass('rate-status-active')) {
                $(that).removeClass('rate-status-active').html('停用');
            } else {
                $(that).addClass('rate-status-active').html('启用');
            }
            $('#operate-after-pop').hide();
        })
        //点击取消
        $('.operate-after-cancel').off('click').on('click', function () {
            $('#operate-after-pop').hide();
        })
    })
    //点击取消
    $('.operate-before-cancel').off('click').on('click', function () {
        $('#operate-before-pop').hide();
    })

}


function activeRule(obj){
    var s = $(obj).attr('data-value');
    var allId = $(obj).attr('id-value');
    var allConfig={allId:allId  };
    var url;
    if(s=="1"){
        url="/operate/stop";
    }else{
        url="/operate/active";
    }
    $.ajax({
        type:"post",
        url:url,
        async:false,
        data:allConfig,
        success:function(){
            alert("保存成功");
            query();
        }
    });
}

function add_show_thpc(){
    $('.rate-project-name').val('');
    $('#thpc_confEname').val('');
    $('.time-range input').val('');
    $('.call-num input').val('');
    $('.rate-remark').val('');
    $('#allIdthpc').val("");
    $('.rate-project-name').removeAttr('readonly');
    $('#thpc_confEname').removeAttr('readonly');
    $('#rate-pop').show();
}function add_show_thxg(){
        $('#confName_edit').val('');
        $('#confEname_edit').val('');
        $('#confValue_edit').val('');
        $('#remark_edit').val( '');
        $('#allIdthxg').val('');
        $('#confName_edit').removeAttr('readonly');
        $('#confEname_edit').removeAttr('readonly');
    $('#result-pop').show();
}


//库存为分 显示为元  所以进行一次转换
function parseValue(name, v ){
if(name.indexOf('price')==-1){
    return v;
} else{
    return  back_money_handler(v/100);
}

}